/*
* Copyright @ 2014 com.iflysse.trains
* manger_v2.0 上午10:57:38
* All right reserved.
*
*/
package com.iflysse.servlet.site;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lxh.smart.File;
import org.lxh.smart.SmartUpload;

import com.iflysse.pojo.SiteInfo;
import com.iflysse.service.SiteInfoService;
import com.iflysse.servlet.util.BaseServlet;

/**
 * @desc: manger_v2.0
 * @author: Administrator
 * @createTime: 2014年11月21日 上午10:57:38
 * @history:
 * @version: v1.0
 */
@WebServlet("/site/siteSubmit.do")
public class SiteSubmitServlet extends BaseServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	@Override
	protected void execute(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		SiteInfo site = new SiteInfo();

		SmartUpload upload=new SmartUpload();
		
		//初始化
		try {
			upload.initialize(this.getServletConfig(), request, response);
			//upload.setMaxFileSize(maxFileSize);
			//upload.setDeniedFilesList("exe,msi");
			//上传
			upload.upload();
			File file= upload.getFiles().getFile(0);
			String logo=file.getFileName();
//			System.out.println(logo);
			file.getContentType();
			//保存在服务端
			String path="fileload/"+logo;
			file.saveAs(path);
			site.setLogo(path);
			//save to db
			//upload.getRequest().getParameter("");
			
			} catch (Exception e) {
				e.printStackTrace();
		}
		
		SiteInfoService service1 = new SiteInfoService();
		if(service1.findSite() == null){
			service1.insertSite(site);
		} else{
			service1.updateSite(site);
		}
//		resp.sendRedirect("site.do");
		
	}
}
